package Controller;

import entity.Emp;
import service.EmpService;
import service.impl.EmpServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
 *徐韬
 *2021/9/23
 *20:29
 */
@WebServlet("/insert")
public class insertEmpController extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("name");
        String salary = request.getParameter("salary");
        String age = request.getParameter("age");
        System.out.println(name);
        System.out.println(salary);
        System.out.println(age);
        Emp emp = new Emp(0,name,Double.valueOf(salary),Integer.valueOf(age));
        EmpService empService = new EmpServiceimpl();
        int i = empService.addEmp(emp);
        if(i>0){
            response.sendRedirect("/ems/ShowAllController");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
